package com.example.photography.fragment.product;

import androidx.core.view.ViewCompat;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.photography.R;
import com.example.photography.adapter.product.MyCourseAdapter;
import com.example.photography.bean.CourseBean;
import com.example.photography.common.BaseFragment;
import com.example.photography.view.MyListView;
import com.loopj.android.http.RequestParams;

import java.util.List;
import java.util.Objects;

import butterknife.BindView;

import static com.example.photography.util.Util.getJson;

/**
 * 圈子
 */
public class My_Course extends BaseFragment {

    @BindView(R.id.lv_item)
    MyListView lvItem;
    private List<CourseBean.CourseListBean> courseListBeans;

    @Override
    protected RequestParams getParams() {
        return null;
    }

    @Override
    protected String getUrl() {
        return null;
    }

    @Override
    protected void initData(String content) {
        //CollapsingToolbarLayout展开/折叠
        ViewCompat.setNestedScrollingEnabled(lvItem,true);
        content = getJson(Objects.requireNonNull(getActivity()), "my_course.json");
        JSONObject jsonObject = JSON.parseObject(content);
        int status = jsonObject.getInteger("code");
        if (status == 202) {
            String data = jsonObject.getString("data");
            //封装转json数据
            courseListBeans = JSONObject.parseArray(JSON.parseObject(data).getString("course_list"), CourseBean.CourseListBean.class);
            initView();
        } else {
            // TODO: 2021/5/2 加没数据的判断
        }

        MyCourseAdapter myContestAdapter = new MyCourseAdapter(courseListBeans,getActivity(),true);
        lvItem.setAdapter(myContestAdapter);
    }

    private void initView() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.lv_course;
    }
}
